public class PDFUtil {
    public String pdf2Pic(String uploadFilePathName) {
        System.out.println("========pdf2Pic========");
        ArrayList<BufferedImage> bufferedImages = PDFUtil.pdf2BufferedImage(uploadFilePathName);
        // 保存图像对象成图片
        String savePath = uploadFilePathName.substring(0,uploadFilePathName.lastIndexOf("."));
        String savePicPath = savePath+"/pic";
        try {
            FileUtil.saveBufferedImage(bufferedImages,savePicPath);
        } catch (IOException e) {
            log.error("保存图片异常！",e);
            return null;
        }
        String zipFilePathName = FileUtil.file2Zip(savePicPath,savePicPath+".zip");
        System.out.println("zipFilePathName = " + zipFilePathName);
        return zipFilePathName;
    }
}

/**
     * PDF 转换成图片对象 BufferedImage
     * @param pdfFileName   PDF文件全路径名
     * @return
     * @throws IOException
     */
    public static ArrayList<BufferedImage> pdf2BufferedImage(String pdfFileName){
        ArrayList<BufferedImage> list = new ArrayList<>();
        PDDocument document = null;
        PDFRenderer pdfRenderer = null;

        try {
            // 加载PDF文件
            document = PDDocument.load(new File(pdfFileName));
            System.out.println("已加载 PDF 文件："+pdfFileName);

            // 创建PDF输入流
            pdfRenderer = new PDFRenderer(document);
            int numberOfPages = document.getNumberOfPages();
            int temp =0;
            if(numberOfPages>20){

            }
            for (int page = 0; page < numberOfPages; ++page) {
                BufferedImage bim = null;
                try {
                    System.out.println("总页数="+numberOfPages+" page = " + (page+1));
                    bim = pdfRenderer.renderImageWithDPI(page,dpi, ImageType.RGB);
                    list.add(bim);
                    bim = null;
                } catch (IOException e) {
                    System.out.println("PDF转换异常...");
                    e.printStackTrace();
                    return null;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            StreamHandler.close(document);
        }
        return list;
    }
